package com.dk.util.file;

import com.dk.util.log.Log;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;

/**
 * yaml文件工具
 */
public class YamlUtil {
    /**
     * PS:读取yaml所有数据
     * @return
     */
    public static Map<String,Map> loadYamlData(String yamlPath) {
        //获取yaml文件对象
        File file = new File(yamlPath);
        //新建yaml文件对象
        Yaml yaml = new Yaml();
        //结果map对象
        Map<String, Map> map = null;
        try {
            //将yaml数据加载到map中
            map = yaml.loadAs(new FileInputStream(file), Map.class);
        } catch (FileNotFoundException e) {
            Log.error("---【error】:yaml文件未找到,文件路径:"+yamlPath+";");
        }
        //新建yaml文件对象
//        Yaml yaml = new Yaml();
//        //结果map对象
//        Map<String, Map> map = yaml.loadAs(YamlUtil.class.getClassLoader().getResourceAsStream(yamlPath), Map.class);
        return map;
    }
}
